export class CreatePolyline {
	defaultArray: any[][] = []
	polylineResult: any[][] = []
	setp: any[] = []
	result: any[][] = []
	constructor() {

	}
	filterData(steps: any[]) {
		const dataArr = steps
		dataArr.forEach((item: any) => {
			if (item.mode === 'WALKING') {
				this.defaultArray.push([item])
			} else {
				this.defaultArray.push([...item.lines])
			}
		})
	}
	setPolylineExchange(arr: any[][], index: number) {
		for (var i = 0; i < arr[index].length; i++) {
			this.setp[index] = arr[index][i];
			if (index != arr.length - 1) {
				this.setPolylineExchange(arr, index + 1)
			} else {
				this.polylineResult.push(JSON.parse(JSON.stringify(this.setp)))
			}
		}

	}
	analysis() {
		console.log('this.polylineResult', this.polylineResult)
		this.polylineResult.forEach((item: any[], index: number) => {
			const arr:any[]=[]
			item.forEach((polylines: any) => {
				var route = polylines
				var coors: any[] = [], pl: any[] = [];

				coors = route.polyline

				//坐标解压（返回的点串坐标，通过前向差分进行压缩）
				var kr = 1000000;
				for (var i = 2; i < coors.length; i++) {
					coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
				}
				//将解压后的坐标放入点串数组pl中
				for (var i = 0; i < coors.length; i += 2) {
					pl.push({ latitude: coors[i], longitude: coors[i + 1] })
				}

				arr.push({
					points: pl,
					color: route.mode === 'WALKING' ? '#666' :index===0? '#f20':'#cccccc',
					width: route.mode === 'WALKING' ? 4 : 8,
					borderColor: route.mode === 'WALKING' ? '#999' : '#f40',
					borderWidth: route.mode === 'WALKING' ? 0 : 1,
					dottedLine: route.mode === 'WALKING' ? true : false,
					
				})
			})

			this.result.push(arr)
		})
	}
	resetData() {
		this.defaultArray.length = 0
		this.polylineResult.length = 0
		this.setp.length = 0
		this.result.length = 0
	}
	init(steps: any[]) {
		// this.resetData()
		this.filterData(steps)
		this.setPolylineExchange(this.defaultArray, 0)

		this.analysis()

		return this.result
	}
}